home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoTemplateChooseDia.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  7.7 KB  |  251 lines

  1. /*
  2.    This file is part of the KDE project
  3.    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
  4.    2000, 2001 Werner Trobin <trobin@kde.org>
  5.    2002, 2003 Thomas Nagy <tnagy@eleve.emn.fr>
  6.    2004 David Faure <faure@kde.org>
  7.  
  8.    This library is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU Library General Public
  10.    License as published by the Free Software Foundation; either
  11.    version 2 of the License, or (at your option) any later version.
  12.  
  13.    This library is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    Library General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU Library General Public License
  19.    along with this library; see the file COPYING.LIB.  If not, write to
  20.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21.  * Boston, MA 02110-1301, USA.
  22.    */
  23.  
  24. #ifndef koTemplateChooseDia_h
  25. #define koTemplateChooseDia_h
  26.  
  27. #include <kdialogbase.h>
  28. #include <kicondialog.h>
  29. #include <kiconview.h>
  30. #include <koffice_export.h>
  31.  
  32. // KoTCD : KoTemplateChooseDia
  33.  
  34. class KoTCDIconViewItem;
  35. class KoTemplateTree;
  36. class KoTemplateGroup;
  37. class QGridLayout;
  38.  
  39. /**
  40.  * Our reimplementation of KIconCanvas used within the template-chooser dialog.
  41.  * @internal
  42.  */
  43. class KoTCDIconCanvas : public KIconCanvas
  44. {
  45.     Q_OBJECT
  46.     public:
  47.     KoTCDIconCanvas( QWidget *parent = 0, const char *name = 0L )
  48.         : KIconCanvas( parent, name ) {}
  49.  
  50.     bool isCurrentValid() { return currentItem(); }
  51.     QIconViewItem * load(KoTemplateGroup *group, const QString& name, KInstance* instance);
  52.  
  53.     protected:
  54.     virtual void keyPressEvent( QKeyEvent *e ) {
  55.         if ( e->key() == Key_Return || e->key() == Key_Enter )
  56.         e->ignore();
  57.         else
  58.         KIconCanvas::keyPressEvent( e );
  59.     }
  60. };
  61.  
  62. /// @internal
  63. class KoTCDIconViewItem : public KIconViewItem
  64. {
  65.     public:
  66.     KoTCDIconViewItem(QIconView *parent=0)
  67.         : KIconViewItem ( parent )
  68.         {}
  69.  
  70.     KoTCDIconViewItem(QIconView *parent=0, const QString &text=0, const QPixmap &icon=0,
  71.                       const QString &descr=0, const QString &fullname=0)
  72.         : KIconViewItem(parent, text, icon)
  73.         {
  74.             m_descr = descr;
  75.             m_full = fullname;
  76.         }
  77.  
  78.     QString getDescr() const { return m_descr; }
  79.     QString getFName() const { return m_full; }
  80.  
  81.     private :
  82.     QString m_descr;
  83.     QString m_full;
  84.  
  85. };
  86.  
  87. #include <kfileiconview.h>
  88. #include <qlabel.h>
  89. /**
  90.  * Our reimplementation of KFileIconView used as the "recent files" view
  91.  * within the template-chooser dialog.
  92.  * @internal
  93.  */
  94. class KoTCDRecentFilesIconView : public KFileIconView {
  95.     Q_OBJECT
  96.     public:
  97.     KoTCDRecentFilesIconView( QWidget* parent, const char* name ) :
  98.         KFileIconView( parent, name ), toolTip(0)
  99.     {
  100.         connect( this, SIGNAL( onItem( QIconViewItem * ) ),
  101.                      SLOT( showToolTip( QIconViewItem * ) ) );
  102.         connect( this, SIGNAL( onViewport() ),
  103.                      SLOT( removeToolTip() ) );
  104.     }
  105.         virtual ~KoTCDRecentFilesIconView();
  106.     protected:
  107.         /**
  108.          * Reimplemented to remove an eventual tooltip
  109.          */
  110.         virtual void hideEvent( QHideEvent * );
  111.  
  112.     private slots:
  113.         void showToolTip( QIconViewItem* );
  114.         void removeToolTip();
  115.     private:
  116.         QLabel* toolTip;
  117. };
  118.  
  119. class KInstance;
  120. class KoTemplateChooseDiaPrivate;
  121.  
  122. /**
  123.  *  This class is used to show the template dialog
  124.  *  on startup. Unless you need something special, you should use the static
  125.  *  method choose().
  126.  *
  127.  *  @short The template choose dialog
  128.  *  @author Reginald Stadlbauer <reggie@kde.org>
  129.  *  @author Werner Trobin <trobin@kde.org>
  130.  */
  131. class KOFFICEUI_EXPORT KoTemplateChooseDia : public KDialogBase
  132. {
  133.     Q_OBJECT
  134.  
  135. public:
  136.     /**
  137.      * The Dialog returns one of these values depending
  138.      * on the input of the user.
  139.      * Cancel = The user pressed 'Cancel'
  140.      * Template = The user selected a template
  141.      * File = The user has chosen a file
  142.      * Empty = The user selected "Empty document"
  143.      */
  144.     enum ReturnType { Cancel, Template, File, Empty };
  145.     /**
  146.      * To configure the dialog you have to use this enum.
  147.      * Everything = Show templates and the rest of the dialog
  148.      * OnlyTemplates = Show only the templates
  149.      * NoTemplates = Just guess :)
  150.      */
  151.     enum DialogType { Everything, OnlyTemplates, NoTemplates };
  152.  
  153.     ~KoTemplateChooseDia();
  154.  
  155.     /**
  156.      * This is the static method you'll normally use to show the
  157.      * dialog.
  158.      *
  159.      * @param instance the KInstance of your app
  160.      * The native mimetype is retrieved from the (desktop file of) that instance.
  161.      * @param file this is the filename which is returned to your app
  162.      * More precisely, it's a url (to give to KURL) if ReturnType is File
  163.      * and it's a path (to open directly) if ReturnType is Template
  164.      *
  165.      * @param dialogType the type of the dialog
  166.      * @param templateType the template type of your application (see kword or
  167.      *        kpresenter for details)
  168.      * @param parent pointer to parent widget
  169.      * @return The return type (see above)
  170.      */
  171.     static ReturnType choose(KInstance* instance, QString &file,
  172.                              const DialogType &dialogType,
  173.                              const QCString& templateType,
  174.                              QWidget* parent);
  175.  
  176. private:
  177.     /// Ditto, with extraNativeMimeTypes added
  178.     static ReturnType choose(KInstance* instance, QString &file,
  179.                              const QCString &format,
  180.                              const QString &nativeName,
  181.                              const QStringList& extraNativeMimeTypes,
  182.                              const DialogType &dialogType=Everything,
  183.                              const QCString& templateType="",
  184.                              QWidget* parent = 0);
  185. public:
  186.  
  187.     /**
  188.      * Method to get the current template
  189.      */
  190.     QString getTemplate() const;
  191.     /**
  192.      * Method to get the "full" template (path+template)
  193.      */
  194.     QString getFullTemplate() const;
  195.     /**
  196.      * The ReturnType (call this one after exec())
  197.      */
  198.     ReturnType getReturnType() const;
  199.     /**
  200.      * The dialogType - normally you won't need this one
  201.      */
  202.     DialogType getDialogType() const;
  203.  
  204. protected slots:
  205.     /**
  206.      * Activated when the Ok button has been clicked.
  207.      */
  208.     virtual void slotOk();
  209.  
  210. private:
  211.     /**
  212.      *
  213.      * @param parent parent the parent of the dialog
  214.      * @param name the Qt internal name
  215.      * @param instance the KInstance of your app
  216.      * @param format is the mimetype of the app (e.g. application/x-kspread)
  217.      * @param nativeName is the name of your app (e.g KSpread)
  218.      * @param dialogType the type of the dialog
  219.      * @param templateType the template type of your application (see kword or
  220.      *        kpresenter for details)
  221.      *
  222.      * @return The return type (see above)
  223.      */
  224.     KoTemplateChooseDia(QWidget *parent, const char *name, KInstance* instance,
  225.                         const QCString &format,
  226.                         const QString &nativeName,
  227.                         const QStringList &extraNativeMimeTypes,
  228.                         const DialogType &dialogType=Everything,
  229.                         const QCString& templateType="");
  230.  
  231. private:
  232.     KoTemplateChooseDiaPrivate *d;
  233.  
  234.     QString descriptionText(const QString &name, const QString &description);
  235.     void setupDialog();
  236.     void setupTemplateDialog(QWidget * widgetbase, QGridLayout * layout);
  237.     void setupFileDialog(QWidget * widgetbase, QGridLayout * layout);
  238.     void setupRecentDialog(QWidget * widgetbase, QGridLayout * layout);
  239.     bool collectInfo();
  240.     bool noStartupDlg() const;
  241.  
  242. private slots:
  243.  
  244.     void chosen(QIconViewItem *);
  245.     void currentChanged( QIconViewItem * );
  246.     void recentSelected( QIconViewItem * );
  247. };
  248.  
  249. #endif
  250.  
  251.